package com.airlines.system.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import com.airlines.system.domain.SysRole;

import java.util.List;

@Mapper
public interface SysRoleMapper {

    int deleteByPrimaryKey(String id);

    int insert(SysRole record);

    int insertSelective(SysRole record);

    SysRole selectByPrimaryKey(String id);

    int updateByPrimaryKeySelective(SysRole record);

    int updateByPrimaryKey(SysRole record);

    /**查询所有的角色*/
    @Select("SELECT * FROM t_sys_role where STATUS =1")
    @ResultMap("com.airlines.system.dao.SysRoleMapper.BaseResultMap")
    List<SysRole> findAll();

    /**查询某一个系统拥有的所有的角色*/
    @Select("SELECT * FROM t_sys_role r " +
            "WHERE " +
            "r.id in (SELECT rt.ROLE_ID from T_SYS_ROLE_TYPE  rt  where  rt.TYPE_ID =#{typeId}) " +
            "AND r.STATUS =1")
    @ResultMap("com.airlines.system.dao.SysRoleMapper.BaseResultMap")
    List<SysRole> findAllByType(@Param("typeId") String typeId);

    /**查询某一个用户在某一个系统拥有的角色*/
    @Select("SELECT * FROM t_sys_role r " +
            "WHERE " +
            "r.id IN ( SELECT ur.ROLE_ID FROM T_SYS_USER_ROLE ur WHERE ur.USER_ID = #{userId}) " +
            "and " +
            "r.id in (SELECT rt.ROLE_ID from T_SYS_ROLE_TYPE  rt  where  rt.TYPE_ID =#{typeId}) " +
            "AND r.STATUS =1")
    @ResultMap("com.airlines.system.dao.SysRoleMapper.BaseResultMap")
    List<SysRole> findByTypeAndUser(@Param("typeId") String typeId ,@Param("userId") String userId);
}